import java.sql.*;

public class DBUtil {

    public static final String driver = "com.mysql.jdbc.Driver";
    public static final String url = "jdbc:mysql://localhost:3306/kgc81?useSSLE=false$serverTimezone=Asia/Shanghai";
    public static final String user = "root";
    public static final String pass = "1234";

    private DBUtil() {
    }

    public static Connection getConnection() {
        try {
            return DriverManager.getConnection(url, user, pass);
        } catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public static void close(ResultSet rs, Statement s, Connection con) {
        close(rs);
        close(s);
        close(con);
    }

    public static void close(Statement s, Connection con) {
        close(s);
        close(con);
    }

    public static void close(ResultSet rs) {
        try {
            if (rs != null && rs.isClosed() == false)
                rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void close(Statement statement) {
        try {
            if (statement != null && statement.isClosed() == false)
                statement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void close(PreparedStatement ps) {
        try {
            if (ps != null && ps.isClosed() == false)
                ps.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void close(Connection connection) {
        try {
            if (connection != null && connection.isClosed() == false)
                connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
